package oa.dao.impl;

import java.util.List;

import oa.base.BaseDao;
import oa.dao.CompanyDao;
import oa.entity.Company;
import oa.exception.DaoException;

public class CompanyDaoImpl extends BaseDao<Company> implements CompanyDao {

	@Override
	public boolean addCompany(Company company) throws DaoException {
		return executeUpdate(
				"INSERT INTO `company` (`company_name`, `company_time`, `company_username`, `company_nature`, `company_scope`, `company_background`, `company_culture`, `company_range`, `company_rule`)VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
				company.getCompanyName(), company.getCompanyTime(), company.getCompanyUsername(),
				company.getCompanyNature(), company.getCompanyScope(), company.getCompanyBackground(),
				company.getCompanyCulture(), company.getCompanyRange(), company.getCompanyRule()) > 0;
	}

	@Override
	public List<Company> selectAllCompany(int companyid) throws DaoException {
		if(companyid==0) {
		return executeQuery("SELECT * FROM company");
		}else {
			return executeQuery("SELECT * FROM company  WHERE company_id =?",companyid);
		}
	}

	@Override
	public List<Company> selectCompany(int companyId) throws DaoException {
		return executeQuery("SELECT * FROM company WHERE company_id = ?", companyId);
	}

	@Override
	public boolean updateCompany(Company company) throws DaoException {
		return executeUpdate(
				"UPDATE `company` SET `company_name`=?, `company_time`=?, `company_username`=?, `company_nature`=?, `company_scope`=?, `company_background`=?, `company_culture`=?, `company_range`=?, `company_rule`=? WHERE (`company_id`=?)",
				company.getCompanyName(), company.getCompanyTime(), company.getCompanyUsername(),
				company.getCompanyNature(), company.getCompanyScope(), company.getCompanyBackground(),
				company.getCompanyCulture(), company.getCompanyRange(), company.getCompanyRule(),company.getCompanyId()) > 0;
	}

	@Override
	public boolean deleteCompany(int companyId) throws DaoException {
		return executeUpdate("DELETE FROM `company` WHERE (`company_id`=?)", companyId) > 0;
	}

}
